<template>
  <div style="height: 100%;">
    <van-nav-bar
      class="header"
      title="编辑个人信息"
      left-text="返回"
      left-arrow
      @click-left="backToCenter">
    </van-nav-bar>
    <div class="main">
      <van-cell-group>
        <van-field
          v-model="userInfo.fusername"
          label="用户姓名："
          name="用户姓名"
          v-validate="'required'"
          data-vv-scope="userEditForm"
          :error="errors.has('userEditForm.用户姓名')"
          :error-message="errors.first('userEditForm.用户姓名')"
          required>
        </van-field>
        <van-field
          v-model="userInfo.fphone"
          label="电话号码："
          name="电话号码"
          v-validate="'required|regex:^(1[0-9]{10})?$'"
          data-vv-scope="userEditForm"
          :error="errors.has('userEditForm.电话号码')"
          :error-message="errors.first('userEditForm.电话号码')"
          required>
        </van-field>
        <van-field
          v-model="userInfo.floginname"
          label="登录名："
          name="登录名"
          v-validate="'required'"
          data-vv-scope="userEditForm"
          :error="errors.has('userEditForm.登录名')"
          :error-message="errors.first('userEditForm.登录名')"
          required>
        </van-field>
        <van-field
          v-model="userInfo.floginpasswd"
          label="登录密码："
          type="password"
          name="登录密码"
          v-validate="'required'"
          data-vv-scope="userEditForm"
          :error="errors.has('userEditForm.登录密码')"
          :error-message="errors.first('userEditForm.登录密码')"
          required>
        </van-field>
        <van-field
          v-model="userInfo.fnickname"
          label="昵称："
          name="昵称"
          readonly>
        </van-field>
        <van-field
          v-model="userInfo.fisstatename"
          label="审批状态："
          readonly>
        </van-field>
        <van-field
          v-model="userInfo.fapprovemessage"
          label="审批信息："
          readonly>
        </van-field>
        <van-field
          v-model="userInfo.fcustomeidname"
          label="所属单位："
          readonly>
        </van-field>
      </van-cell-group>
      <div style="padding: 10px 16px;text-align: right">
        <van-button @click="save" size="small" type="info">保存</van-button>
        <!-- <van-button size="small" plain type="info">取消</van-button> -->
      </div>
    </div>
    <footer-btn></footer-btn>
  </div>
</template>

<script>
import Cookies from 'js-cookie'
import {
  NavBar,
  Button,
  CellGroup,
  Field,
  Toast,
} from 'vant'
import footerBtn from '@/components/footerBtn'
import { redirect_my, system_customer_user_edit } from '@/api/user'
export default {
  name: 'userEdit',
  components: {
    footerBtn,
    [NavBar.name]:NavBar,
    [Button.name]:Button,
    [CellGroup.name]:CellGroup,
    [Field.name]:Field,
  },
  created() {
    this.userid = 'bb5a8fe0-e03e-42ba-a1ed-279bba27b3a3'
    this.getData()
  },
  data() {
    return {
      userid: Cookies.get('fusreid'),
      userInfo: {},
      customeInfo: {}
    }
  },
  methods: {
    getData() {
      const _this = this
      redirect_my({
        userid: _this.userid
      }).then(res => {
        const userInfo = res.sysparams.users
        // const customeInfo = res.sysparams.limsCustome
        for (const key in userInfo) {
          _this.$set(_this.userInfo, key, userInfo[key])
        }
        // for (const key in customeInfo) {
        //   _this.$set(_this.customeInfo, key, customeInfo[key])
        // }
      })
    },
    backToCenter() {
      history.go(-1)
    },
    save() {
      this.$validator.validateAll('userEditForm').then((valid) => {
        if (valid) {
          system_customer_user_edit(this.userInfo).then(res => {
            if (res.isSuccess) {
              Toast.success('保存成功！')
              this.$router.push({ path: '/center' })
            } else {
              Toast.fail('保存失败')
            }
          })
        } else {
          Toast.fail('请输入正确的信息！')
        }
      })
    }
  }
}
</script>

<style>

</style>